import 'package:flutter/material.dart';

import '../../chat_core/network/connection/msg_manager.dart';
import 'ListComponentPage.dart';

class ChatRelinkWidget extends StatelessWidget {
  final SocketStateEnum socketType;
  final String pointText;
  final BuildContext context;
  // final Dispatch dispatch;
  ChatRelinkWidget(this.socketType, this.pointText, this.context);
  @override
  Widget build(BuildContext context) => textItem();

  Widget textItem() {
    return Container(
      width: MediaQuery.of(context).size.width * 0.67,
      margin: EdgeInsets.only(left: 10, right: 10, top: 10),
      padding: EdgeInsets.all(10),
      child: ConstrainedBox(
        constraints: BoxConstraints(
            minHeight: 0,
            maxWidth: MediaQuery.of(context).size.width * 0.5),
        child: Center(
            child: Column(
          children: <Widget>[
            Visibility(
                visible: socketType == SocketStateEnum.ERROR,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Text("连接失败..."),
                    SizedBox(width: 20),
                    Container(
                      width: 120,
                      height: 30,
                      child: GestureDetector(
                        onTap: () {
                          GlobalKey<ListComponentPageState>  listComponentPageState = GlobalKey();
                          listComponentPageState.currentState?.reconnectAfterDisconnection();
                        },
                        child: Text(
                          "重新连接",
                          style: TextStyle(color: Colors.white, fontSize: 12),
                        ),
                      ),
                    )
                  ],
                )),
            Visibility(
                visible: socketType == SocketStateEnum.CONNECTING,
                child: Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text(pointText),
                    ],
                  ),
                ))
          ],
        )),
      ),
    );
  }
}
